package cn.doitedu.day03


object FoldRightDemo {


  def main(args: Array[String]): Unit = {

    val arr = Array(1,2,3,4,5,6)


    val r1 = arr.foldLeft(0)(_ - _)
    println(r1)

    //6 - 0 = 6
    //5 - 6 = -1
    //4 - (-1) = 5
    //3 - 5 = -2
    //2 - (-1) = 4
    //1 - 4 = -3
    val r2 = arr.foldRight(0)(_ - _)
    print(r2)



  }

}
